package filter;

import servlet.Login;
import validation.Validation;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.net.CookieStore;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by v on 17-5-7.
 */
@WebFilter(filterName = "LoginFilter",value = "/login.html")
public class LoginFilter implements Filter{
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request=(HttpServletRequest)servletRequest;
        HttpServletResponse response=(HttpServletResponse)servletResponse;

        //判断是否需要登录
        if (!Validation.LoginValidation(request,response)){
            filterChain.doFilter(servletRequest,servletResponse);
        }else {
            response.sendRedirect("/home.html");
        }

    }
}
